/*
package cn.cnic.user.component.system.service.Impl;

import cn.cnic.user.utils.*;
import cn.cnic.user.component.system.model.User;
import cn.cnic.user.mapper.system.UserMapper;
import cn.cnic.user.component.system.service.IUserServices;
import cn.cnic.user.vo.IUserVo;
import cn.cnic.user.vo.UserVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;

@Component
public class UserServicesImpl implements IUserServices {

    Logger logger = LoggerUtil.getLogger();

    @Resource
    UserMapper userMapper;

    @Override
    public String checkUserName(String username) {
        Map<String, String> rtnMap = new HashMap<String, String>();
        rtnMap.put("code", "0");
        if (StringUtils.isNotBlank(username)) {
            User user = userMapper.getUserByUsername(username);
            if (null != user) {
                rtnMap.put("errMsg", "Username is already taken");
                logger.info("用户名被占用");
            } else {
                rtnMap.put("code", "1");
                rtnMap.put("errMsg", "Username is available");
            }
        } else {
            rtnMap.put("errMsg", "Username can not be empty");
            logger.info("用户名不能为空");
        }
        JsonUtils.toJsonNoException(rtnMap);
        return null;
    }

    @Override
    public String addUser(UserVo userVo) {
        Map<String, String> rtnMap = new HashMap<String, String>();
        rtnMap.put("code", "0");
        if (null != userVo) {
            String username = userVo.getUsername();
            String password = userVo.getPassword();
            if (!StringUtils.isAnyEmpty(username, password)) {
                //加密密码
                password = new BCryptPasswordEncoder().encode(password);
                User sysUser = new User();
                //sysUser.setId(SqlUtils.getUUID32());
                sysUser.setCreateDate(new Date());
                sysUser.setModifyDate(new Date());
                sysUser.setUsername(username);
                sysUser.setPassword(password);
                sysUser.setName(userVo.getName());
                sysUser.setAge(userVo.getAge());
                sysUser.setSex(userVo.getSex());
                sysUser.setDepartment(userVo.getDepartment());
                sysUser.setIdCard(userVo.getIdCard());
                sysUser.setOrganId(userVo.getOrganId());

                int addUser = userMapper.addUser(sysUser);
                if (addUser > 0) {
                    rtnMap.put("code", "1");
                    rtnMap.put("errMsg", "恭喜你, 注册成功");
                } else {
                    rtnMap.put("errMsg", "注册失败, 保存失败");
                    logger.info("注册失败，保存失败");
                }
            } else {
                rtnMap.put("errMsg", "注册失败，用户名或密码为空");
                logger.info("注册失败，用户名或密码为空");
            }
        } else {
            rtnMap.put("errMsg", "注册失败");
            logger.info("注册失败");
        }
        return JsonUtils.toJsonNoException(rtnMap);
    }

    @Override
    public String getUserListPage(Integer offset, Integer limit, String param) {
        Map<String, Object> rtnMap = new HashMap<String, Object>();
        IUserVo currentUser = SessionUserUtil.getCurrentUser();
        if (null != offset && null != limit) {
            Page page = PageHelper.startPage(offset, limit);
            userMapper.getUserListParam(param);
            rtnMap = PageHelperUtils.setDataTableParam(page, rtnMap);
            rtnMap.put("code", 200);
        }
        return JsonUtils.toJsonNoException(rtnMap);
    }

    @Override
    public UserVo getUserById(String id) {
        UserVo userVo = null;
        if (StringUtils.isNotBlank(id)) {
            Integer idNum = Integer.parseInt(id);
            User user = userMapper.getUserById(idNum);
            if (null != user) {
                userVo = new UserVo();
                BeanUtils.copyProperties(user, userVo);
            }
        }
        return userVo;
    }
}
*/
